from flask import Blueprint, make_response
from flask_restful import Api
from app.api.resources.users import Users, UsersList
import json
from flask_restful.utils import OrderedDict

bp = Blueprint('api', __name__)

api = Api(bp)


@api.representation('application/json')
def output_json(data, code, headers=None):
    resp_data = OrderedDict({'success': code})
    resp_data.update(data)
    resp = make_response(json.dumps(resp_data), code)
    resp.headers.extend(headers or {})
    return resp


api.add_resource(UsersList, '/users')
api.add_resource(Users, '/users/<int:id>')
